<template>
    <view>
        <u-navbar title="拼团" safeAreaInsetTop fixed placeholder>
            <view class="coreshop-navbar-left-slot" slot="left">
                <u-icon name="arrow-left" size="19" @click="goNavigateBack"></u-icon>
                <u-line direction="column" :hairline="false" length="16" margin="0 8px"></u-line>
                <u-icon name="home" size="22" @click="goHome"></u-icon>
            </view>
            <view slot="right">
            </view>
        </u-navbar>
        <view class="content">
            <!-- 列表图片 -->
            <scroll-view class="scroll-box" scroll-y>
                <view class="group-wrap coreshop-bg-red">
                    <view class="group-head coreshop-flex coreshop-justify-between">
                        <text class="group-head__title">爆款推荐</text>
                        <text class="group-head__notice">省钱省心限时拼</text>
                    </view>
                    <view class="group-box" v-if="list.length>0">
                        <view class="goods-item" v-for="(item, index) in list" :key="item.id">
                            <view class="coreshop-flex coreshop-justify-start coreshop-padding-left-10 coreshop-padding-top-10  coreshop-padding-bottom-10">
                                <view>
                                    <view class="tag" v-if="index < 3">TOP{{ index + 1 }}</view>
                                    <u--image :src="item.goodThumbnail" mode="widthFix" width="100px" height="100px" radius="10"></u--image>
                                </view>
                                <view class="goods-right coreshop-flex coreshop-flex-direction  coreshop-padding-left-10 coreshop-padding-right-10 coreshop-percent-100">
                                    <view class="title u-line-2 coreshop-text-black">{{ item.name }}</view>
                                    <view class="tip u-line-2 coreshop-text-grey">{{ item.goodName }}</view>
                                    <view class="coreshop-flex coreshop-align-center coreshop-padding-top-10  coreshop-padding-bottom-10">
                                        <view class="coreshop-font-11 coreshop-bg-green coreshop-padding-2 coreshop-border-radius-4 coreshop-margin-right-10">已拼{{item.buyPinTuanCount}}单</view>
                                        <view class="coreshop-font-11 coreshop-bg-orange coreshop-padding-2 coreshop-border-radius-4 coreshop-margin-right-10">已售{{item.pinTuanRecordNums}}{{item.goodUnit}}</view>
                                        <view class="coreshop-font-11 coreshop-bg-olive coreshop-padding-2 coreshop-border-radius-4">{{item.peopleNumber}}人团</view>
                                    </view>
                                    <view class="coreshop-flex coreshop-justify-between  coreshop-flex-direction-row coreshop-align-center">
                                        <view class="coreshop-flex coreshop-align-center">
                                            <view class="current">￥{{ item.pinTuanPrice  }}</view>
                                            <view class="original">￥{{ item.mktPrice }}</view>
                                        </view>
                                        <view class="coreshop-buy-btn" @tap="goPinTuanDetail(item.id)">马上拼</view>
                                    </view>
                                </view>
                            </view>
                        </view>
                        <u-loadmore :status="status" :icon-type="iconType" :load-text="loadText" margin-top="20" margin-bottom="20" />
                    </view>
                    <!-- 无数据时默认显示 -->
                    <view class="coreshop-emptybox" v-else>
                        <u-empty :icon="$globalConstVars.apiFilesUrl+'/static/images/empty/history.png'" icon-size="150" text="暂无提现明细" mode="list"></u-empty>
                    </view>
                </view>
                <!-- 空白 -->
            </scroll-view>
        </view>
        <!-- 登录提示 -->
        <coreshop-login-modal></coreshop-login-modal>
    </view>
</template>

<script>
    var _this;
    export default {
        data() {
            return {
                page: 1,
                limit: 10,
                list: [],
                status: 'loadmore',
                iconType: 'flower',
                loadText: {
                    loadmore: '轻轻上拉',
                    loading: '努力加载中',
                    nomore: '实在没有了'
                }
            };
        },
        onLoad() {
            this.getPinTuanlist()
        },
        onShow() {
        },
        onReachBottom() {
            if (this.status === 'loadmore') {
                this.getPinTuanlist()
            }
        },
        methods: {
            getPinTuanlist() {
                let _this = this;
                let data = {
                    page: this.page,
                    limit: this.limit
                }
                this.status = 'loading'
                this.$u.api.pinTuanList(data).then(res => {
                    if (res.status) {
                        if (res.data) {
                            let _list = res.data
                            this.list = [...this.list, ..._list]
                        }
                        if (res.code >= _this.list.length) {
                            _this.page++
                            _this.status = 'loadmore'
                        } else {
                            _this.status = 'nomore'
                        }
                    } else {
                        _this.$u.toast(res.msg)
                    }
                })
            },
            //取得列表数据
            getGoods: function () {
                uni.showLoading({
                    title: '加载中',
                    mask: true
                });
                var _this = this;
                _this.$u.api.pinTuanList().then(res => {
                    if (res.status) {
                        _this.goodsList = res.data;
                        if (_this.goodsList) {
                            _this.goodsList.forEach(item => {
                                if (item.pinTuanPrice <= 0) {
                                    item.pinTuanPrice = '0.00';
                                } else {
                                    item.pinTuanPrice = parseFloat(item.price - item.pinTuanRule.discountAmount).toFixed(2);
                                }
                            });
                        }
                        uni.hideLoading();
                    } else {
                        uni.hideLoading();
                    }
                });
            }
        }
    };
</script>

<style lang="scss">
    @import "list.scss";
</style>
